/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.autoescola.core.web.security;

import java.io.IOException;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.inject.Scope;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

/**
 *
 * @author leonardo luz fernandes
 * @version 0.1
 * 
 */

//@Component
//@Scope("request")
@ManagedBean(name="loginController")
@RequestScoped
public class LoginController {

    private String user;
    private String password;
    private boolean storeUser = false;
    private boolean logIn = false;
    
    public String getUser(){
        return this.user ;
    }//end method
    
    public void setUser( final String user ){
        this.user = user ;
    }//end method

    public String getPassword(){
        return this.password ;
    }//end method
    
    public void setPassword( final String password ){
        this.password = password ;
    }//end method
    
    public boolean isStoreUser(){
        return this.storeUser;
    }//end method
    
    public void setStoreUser( final boolean storeUser ){
        this.storeUser = storeUser;
    }//end method
    
    public boolean isLogIn(){
        return this.logIn;
    }//end method
    
    public void setLogIn( final boolean logIn ){
        this.logIn = logIn;
    }//end method
    
    public String loginAction() throws IOException , ServletException {

        ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
        RequestDispatcher dispatcher = ((ServletRequest)context.getRequest()).getRequestDispatcher("/j_spring_security_check");
        dispatcher.forward((ServletRequest)context.getRequest(),(ServletResponse)context.getResponse());
        FacesContext.getCurrentInstance().responseComplete();     
        
        return null;
                
    }//end method

}//end klazz
